package com.financing.platform.web;

import java.io.File;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.ModelAndView;

import com.financing.platform.dto.CompanyDTO;
import com.financing.platform.dto.CorpProjectDTO;
import com.financing.platform.dto.ProductAttachmentDTO;
import com.financing.platform.dto.ProductRecommendDTO;
import com.financing.platform.dto.ProjectAccountDTO;
import com.financing.platform.dto.ProjectAnnualRevenueDTO;
import com.financing.platform.dto.ProjectCommentsDTO;
import com.financing.platform.dto.ProjectDTO;
import com.financing.platform.dto.ProjectRabateDTO;
import com.financing.platform.dto.ProjectRiskDTO;
import com.financing.platform.service.ICompanyService;
import com.financing.platform.service.IProductRecommendService;
import com.financing.platform.service.IProjectAccountService;
import com.financing.platform.service.IProjectAnnualRevenueService;
import com.financing.platform.service.IProjectRabateService;
import com.financing.platform.service.IProjectRiskService;
import com.financing.platform.service.IProjectService;
import com.financing.platform.util.DTOdateSet;
import com.financing.platform.util.Dict;
import com.financing.platform.util.FileUtil;
import com.financing.platform.util.StringUtil;
import com.financing.platform.vo.ProjectVO;

@Controller
public class ProjectAction extends BaseAction{
	
	@Autowired
	private IProjectService projectServiceImpl;
	
	@Autowired
	private IProjectAnnualRevenueService projectAnnualRevenueServiceImpl; 
	
	@Autowired
	private IProjectRabateService projectRabateSericeImpl;
	
	@Autowired
	private IProjectRiskService projectRiskServiceImpl;
	
	@Autowired
	private IProductRecommendService productRecommendServiceImpl;
	
	@Autowired
	private ICompanyService companyServiceImpl;
	
	@Autowired
	private IProjectAccountService projectAccountServiceImpl;
	
	@Value("#{settings['fileBaseDir']}")
	private String fileBaseDir;
	
	@Value("#{settings['productFileDir']}")
	private String fileDir;
	
	@RequestMapping("/addProjectPer.shtml")
	public ModelAndView addProjectPer(HttpServletRequest request,
			HttpServletResponse response) {
			request.getSession().setAttribute(Dict.requestID, "addProjectPer.shtml");
			
			List<CompanyDTO> companyList = 	companyServiceImpl.listCompany(null);
			
			Map<String,Object> resultMap = new HashMap<String,Object>();
			resultMap.put("companyList", companyList);
			
			return new ModelAndView("addProjectPer",resultMap);
	}
	
	@RequestMapping("/addProject.shtml")
	public ModelAndView addProject(HttpServletRequest request,
			HttpServletResponse response,ProjectDTO projectDTO,CorpProjectDTO corpProjectDTO) {
			Map<String,Object> resultMap = new HashMap<String,Object>();
			resultMap.put(Dict.result, 1);
			
			projectDTO.setStatus(Dict.pProductStatus_need_Verify);
			projectDTO.setpPublicStatus(Dict.pPublicStatus_No_public);
			DTOdateSet.setCreateInfo(projectDTO, request.getSession());
			DTOdateSet.setUpdateInfo(projectDTO, request.getSession());
			
			DTOdateSet.setCreateInfo(corpProjectDTO, request.getSession());
			DTOdateSet.setUpdateInfo(corpProjectDTO, request.getSession());
			
			projectDTO.setpExpectSubscriptionAmount(projectDTO.getpIssuingScale());
			//将页面的万元单位换算为元
			if(projectDTO.getpIssuingScale() != null){
				projectDTO.setpIssuingScale(projectDTO.getpIssuingScale().multiply(new BigDecimal(100000000)));
			}
			
			if(projectDTO.getpExpectSubscriptionAmount() != null){
				projectDTO.setpExpectSubscriptionShare(projectDTO.getpExpectSubscriptionAmount().multiply(new BigDecimal(100000000)));
			}
			if(projectDTO.getpMinimumAmount() != null){
				projectDTO.setpMinimumAmount(projectDTO.getpMinimumAmount().multiply(new BigDecimal(10000)));
			}
			if(projectDTO.getpExpectSubscriptionAmount() != null){
				projectDTO.setpExpectSubscriptionAmount(projectDTO.getpExpectSubscriptionAmount().multiply(new BigDecimal(100000000)));
			}
			if(projectDTO.getpProgressiveAmount() != null){
				projectDTO.setpProgressiveAmount(projectDTO.getpProgressiveAmount().multiply(new BigDecimal(10000)));
			}
			
			int project = 0;
			try {
				project = projectServiceImpl.addProject(projectDTO,corpProjectDTO,uploadProductFiles(request,projectDTO));
				projectDTO.setId(project);
			} catch (Exception e) {
				log.error("Add project error !",e);
				resultMap.put(Dict.result, 0);
			}
			
			resultMap.put(Dict.projectDTO, projectDTO);
			resultMap.put("corpProjectDTO", corpProjectDTO);
			return new ModelAndView("addProjectResult",resultMap);
				
	}
	
	/**
	 * 
	* @Title: uploadProductFiles 
	* @Description: 保存附件
	* @param   request
	* @return List<ProductAttachmentDTO>   
	* @throws
	 */
	private  List<ProductAttachmentDTO> uploadProductFiles(HttpServletRequest request,ProjectDTO projectDTO) throws Exception{
		
		List<ProductAttachmentDTO> productAttachmentDTOList = new ArrayList<ProductAttachmentDTO>() ;
		
		CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());
		if(multipartResolver.isMultipart(request))
        {
            //将request变成多部分request
            MultipartHttpServletRequest multiRequest=(MultipartHttpServletRequest)request;
           //获取multiRequest 中所有的文件名
            Map<String,MultipartFile> mutipartFileMap = multiRequest.getFileMap();
             
            Iterator<Entry<String, MultipartFile>> mutipartFileIterator =  mutipartFileMap.entrySet().iterator();
            while(mutipartFileIterator.hasNext())
            {
            	Entry<String, MultipartFile> entry = mutipartFileIterator.next();
                MultipartFile file=entry.getValue();
                if(file!=null && (!file.isEmpty()) &&  (!StringUtil.isNullOrEmptyStr(entry.getKey())))
                {
                	StringBuffer fileFullPath = new StringBuffer();
                	fileFullPath.append(fileBaseDir)
                				.append(fileDir)
                				.append("/")
                				.append(StringUtil.dateNowStr("yyyyMMdd"))
                				.append("/")
                				.append(System.currentTimeMillis())
								.append(file.getOriginalFilename());
                	File dir = new File(fileFullPath.toString());
                	if(!dir.exists()){
                		dir.mkdirs();
                	}
                	
                	//上传
                    FileUtil.saveFile(file, fileFullPath.toString());
                    
                	if("image".equals(entry.getKey())){
                		projectDTO.setpImageUri(fileFullPath.toString().substring(fileBaseDir.length()));
                	}else{
	                    ProductAttachmentDTO productAttachmentDTO = new ProductAttachmentDTO();
	                    productAttachmentDTO.setfName(file.getOriginalFilename());
	                    productAttachmentDTO.setfUploadTime(new Date());
	                    productAttachmentDTO.setfType(file.getContentType());
	                    productAttachmentDTO.setfPath(fileFullPath.toString().substring(fileBaseDir.length()));
	                    productAttachmentDTOList.add(productAttachmentDTO);
                	}
                }
                 
            }
           
        }
		
		return productAttachmentDTOList;
		
	}
	
	@RequestMapping("/addProjectAccount.shtml")
	@Transactional
	public ModelAndView addProjectAccount(HttpServletRequest request,
			HttpServletResponse response,ProjectDTO projectDTO) {
		
		Map<String,Object> result = new HashMap<String,Object>();
		result.put(Dict.result, 1);
		
		String[] pProjectId = request.getParameterValues("pProjectId");
		String[] pRaiseAccountName = request.getParameterValues("pRaiseAccountName");
		String[] pRaiseAccountNo = request.getParameterValues("pRaiseAccountNo");
		String[] pRaiseAccountOpenAddr =request.getParameterValues("pRaiseAccountOpenAddr");

		ProjectAccountDTO projectAccountDTO = new ProjectAccountDTO();
		DTOdateSet.setCreateInfo(projectAccountDTO, request.getSession());
		DTOdateSet.setUpdateInfo(projectAccountDTO, request.getSession());
		
		for(int i = 0 ;i < pProjectId.length ; i++){
			if(!StringUtil.isNullOrEmptyStr(pRaiseAccountNo[i])){
				projectAccountDTO.setpProjectId(pProjectId[i]);
				projectAccountDTO.setpRaiseAccountName(pRaiseAccountName[i]);
				projectAccountDTO.setpRaiseAccountNo(pRaiseAccountNo[i]);
				projectAccountDTO.setpRaiseAccountOpenAddr(pRaiseAccountOpenAddr[i]);
				try {
					projectAccountServiceImpl.addProjectAccount(projectAccountDTO);
				} catch (SQLException e) {
					log.error("add project account error " ,e);
					result.put(Dict.result, 0);
				}
			}
		}
		result.put("pId", projectDTO.getId());
		return new ModelAndView("addProjectAnnualRevenueResult",result);
	}
	
	/**
	 * 
	* @Title: addProjectAnnualRevenuePer 
	* @Description: 添加年化益准备页
	* @param   projectDTO
	* @return ModelAndView   
	* @throws
	 */
	@RequestMapping("/addProjectAnnualRevenuePer.shtml")
	public ModelAndView addProjectAnnualRevenuePer(ProjectDTO projectDTO){
		Map<String,Object> resultMap = new HashMap<String,Object>();
		resultMap.put(Dict.result, 1);
		resultMap.put("pId", projectDTO.getId());
		return new ModelAndView("addProjectResult",resultMap);
	}
	
	/**
	 * 
	* @Title: addProjectAnnualRevenue 
	* @Description: 添加产品年化益率和返佣
	* @param   request
	* @param   response
	* @param   projectAnnualRevenueDTO
	* @return ModelAndView   
	* @throws
	 */
	@RequestMapping("/addProjectAnnualRevenue.shtml")
	@Transactional
	public ModelAndView addProjectAnnualRevenue(HttpServletRequest request,
			HttpServletResponse response) {
		
		Map<String,Object> result = new HashMap<String,Object>();
		
		String[] projectId = request.getParameterValues("pId");
		String[] pAnnualRevenueExpect = request.getParameterValues("pAnnualRevenueExpect");
		String[] pStartAmount = request.getParameterValues("pStartAmount");
		String[] pEndAmount =request.getParameterValues("pEndAmount");
		String[] pRabateType = request.getParameterValues("pRabateType");
		String[] pRabateProfit = request.getParameterValues("pRabateProfit");
		
		ProjectDTO project = new ProjectDTO();
		
		for(int i = 0;i<projectId.length; i++){
			
			project.setId(Integer.valueOf(projectId[i]));
			
			project = projectServiceImpl.queryProject(project);
			if(null == project || project.getId() == null){
				continue;
			}
			
			ProjectAnnualRevenueDTO projectAnnualRevenueDTO = new ProjectAnnualRevenueDTO();
			ProjectRabateDTO projectRabateDTO = new ProjectRabateDTO();
			
			projectAnnualRevenueDTO.setpAnnualRevenueExpect(pAnnualRevenueExpect[i]);
			projectAnnualRevenueDTO.setpStartAmount(new BigDecimal(pStartAmount[i]).multiply(new BigDecimal(10000)));
			projectAnnualRevenueDTO.setpEndAmount(new BigDecimal(pEndAmount[i]).multiply(new BigDecimal(10000)));
			projectAnnualRevenueDTO.setpId(Integer.valueOf(projectId[i]));
			if(pRabateType != null && pRabateType.length > 0){
				projectRabateDTO.setpRabateProfit(new BigDecimal(pRabateProfit[i]));
				projectRabateDTO.setpRabateType(pRabateType[i]);
				projectRabateDTO.setpId(Integer.valueOf(projectId[i]));
				DTOdateSet.setCreateInfo(projectRabateDTO, request.getSession());
				DTOdateSet.setUpdateInfo(projectRabateDTO, request.getSession());
			}
			
			DTOdateSet.setCreateInfo(projectAnnualRevenueDTO, request.getSession());
			DTOdateSet.setUpdateInfo(projectAnnualRevenueDTO, request.getSession());
			
			int arId = projectAnnualRevenueServiceImpl.insertProjectAnnualRevenue(projectAnnualRevenueDTO);
			//arId 为-1 则年化益率插入失败
			if(arId == -1){
				result.put(Dict.result, 0);
				break;
			}
			if(pRabateType != null && pRabateType.length > 0){
				projectRabateDTO.setArId(arId);
				projectRabateSericeImpl.addProjectRabateInfo(projectRabateDTO);
			}
			result.put(Dict.result, 1);
		}
		
		project.setId(Integer.valueOf(request.getParameter("id")));
		
		result.put("project", project);
		//添加成功 继续添加
		return new ModelAndView("addProjectAccount",result);
		
	}
	
	/**
	 * 
	* @Title: addProjectRisk 
	* @Description: 添加产品风控信息
	* @param   request
	* @param   response
	* @param   projectRiskDTO
	* @param   projectCommentsDto
	* @return ModelAndView   
	* @throws
	 */
	@RequestMapping("/addProjectRisk.shtml")
	@Transactional
	public ModelAndView addProjectRisk(HttpServletRequest request,
			HttpServletResponse response,ProjectRiskDTO projectRiskDTO) {
		
		DTOdateSet.setCreateInfo(projectRiskDTO, request.getSession());
		DTOdateSet.setUpdateInfo(projectRiskDTO, request.getSession());
		
		Map<String,Object> resultMap = new HashMap<String,Object>();
		
		resultMap.put(Dict.result, projectRiskServiceImpl.addProjectRisk(projectRiskDTO));
		
		return new ModelAndView("addProjectRiskResult",resultMap);
		
	}
	
	
	@RequestMapping("/queryProjectListForPublishPer.shtml")
	public ModelAndView queryProjectListForPublishPer(HttpServletRequest request,
			HttpServletResponse response,ProjectDTO projectDTO) {
			request.getSession().setAttribute(Dict.requestID, "queryProjectListForPublishPer.shtml");
			return new ModelAndView("projectListForPublishPer");
	}
	
	@RequestMapping("/queryProjectListForPublish.shtml")
	public ModelAndView queryProjectListForPublish(HttpServletRequest request,
			HttpServletResponse response,ProjectDTO projectDTO) {
			log.info("Begin query project list for publish !");
			
			List<ProjectVO> listProjectVO = null;
			try {
				listProjectVO = projectServiceImpl.projectListForPublish(projectDTO);
			} catch (SQLException e) {
				log.error("query product for publish  error!",e);
				listProjectVO = Collections.emptyList();
			}
			
			Map<String,Object> projectMap = new HashMap<String,Object>();
			projectMap.put("projectList", listProjectVO);
			projectMap.put("projectDTO", projectDTO);
			
			log.info("End query project list for publish !");
			return new ModelAndView("projectListForPublish",projectMap);
	}
	
	@RequestMapping("/queryProjectForPublish.shtml")
	public ModelAndView queryProjectForPublish(HttpServletRequest request,
			HttpServletResponse response,ProjectDTO projectDTO) {
		
			ProjectDTO  project = projectServiceImpl.queryProject(projectDTO);
			
			ProjectCommentsDTO  projectComments = new ProjectCommentsDTO();
			projectComments.setpId(project.getId());
			
			//查询点评信息
//			List<ProjectCommentsDTO>  projectCommentsList =   projectCommentsServiceImpl.queryProjectComments(projectComments); 
			
			//查询年化益率信息
			List<ProjectAnnualRevenueDTO> projectAnnualRevenueList = projectAnnualRevenueServiceImpl.queryProjectAnnualRevenue(project.getId());
			
			ProjectRabateDTO projectRabateDTO = new ProjectRabateDTO();
			projectRabateDTO.setpId(project.getId());
			List<ProjectRabateDTO>  projectRabateList = projectRabateSericeImpl.queryProjectRabate(projectRabateDTO);
			
			ProjectRiskDTO projectRiskDto = new ProjectRiskDTO();
			projectRiskDto.setpId(project.getId());
			List<ProjectRiskDTO> projectRiskList = projectRiskServiceImpl.queryProjectRisk(projectRiskDto);
			
			ProductRecommendDTO productRecommendDto = new ProductRecommendDTO();
			productRecommendDto.setFpProjectId(project.getId());
			
			List<ProjectAccountDTO>  projectAccountList = projectAccountServiceImpl.queryProjectAccountList(project.getId());
			Map<String,Object> projectMap = new HashMap<String,Object>();
			try {
				CorpProjectDTO corpProjectDTO = projectServiceImpl.queryCorpProject(project.getId());
				if(corpProjectDTO != null &&  corpProjectDTO.getFpCorpId() != null && 0!=corpProjectDTO.getFpCorpId()){
					CompanyDTO companyDTO = new CompanyDTO();
					companyDTO.setId(corpProjectDTO.getFpCorpId());
					projectMap.put("projectCorpList",companyServiceImpl.listCompany(companyDTO));
				}
			} catch (SQLException e) {
				log.error("query project corp error:",e);
			}
			
			projectMap.put("project", project);
			projectMap.put("projectRiskList", projectRiskList);
			projectMap.put("projectRabateList", projectRabateList);
			projectMap.put("projectAnnualRevenueList", projectAnnualRevenueList);
			projectMap.put("projectAccountList", projectAccountList);
//			projectMap.put("projectCommentsList", projectCommentsList);
			
			return new ModelAndView("projectPublishModify",projectMap);
	}
	

	@RequestMapping("/updateProjectForPublish.shtml")
	public ModelAndView updateProjectForPublish(HttpServletRequest request,
			HttpServletResponse response,ProjectDTO projectDTO) {
		
			DTOdateSet.setUpdateInfo(projectDTO, request.getSession());
			int project = 0;
			try {
				project = projectServiceImpl.updateProject(projectDTO,null);
			} catch (SQLException e) {
				log.error("Update project error!",e);
			}
			
			Map<String,Object> resultMap = new HashMap<String,Object>();
			resultMap.put(Dict.result, project);
			
			return new ModelAndView("projectPublishModifyResult",resultMap);
	}
	
	@RequestMapping("/queryProjectListForVerifyPer.shtml")
	public ModelAndView queryProjectListForVerifyPer(HttpServletRequest request,
			HttpServletResponse response,ProjectDTO projectDTO) {
		request.getSession().setAttribute(Dict.requestID, "queryProjectListForVerifyPer.shtml");
		return new ModelAndView("projectListForVerifyPer");
	}
	
	
	@RequestMapping("/queryProjectListForVerify.shtml")
	public ModelAndView queryProjectListForVerify(HttpServletRequest request,
			HttpServletResponse response,ProjectDTO projectDTO) {
		log.info("Begin query project list for Verify !");
		
		projectDTO.setpPublicStatus(Dict.pPublicStatus_No_public);
		projectDTO.setStatus(Dict.pProductStatus_need_Verify);
		List<ProjectDTO> listProjectDTO = projectServiceImpl.queryAllProject(projectDTO);
		
		Map<String,Object> projectList = new HashMap<String,Object>();
		projectList.put("projectList", listProjectDTO);
		projectList.put("projectDTO", projectDTO);
		
		log.info("End query project list for Verify !");
		return new ModelAndView("projectListForVerify",projectList);
	}
	
	@RequestMapping("/queryProjectForVerify.shtml")
	public ModelAndView queryProjectForVerify(HttpServletRequest request,
			HttpServletResponse response,ProjectDTO projectDTO) {
		projectDTO.setpPublicStatus(Dict.pPublicStatus_No_public);
		projectDTO.setStatus(Dict.pProductStatus_need_Verify);
		ProjectDTO  project = projectServiceImpl.queryProject(projectDTO);
		
		ProjectCommentsDTO  projectComments = new ProjectCommentsDTO();
		projectComments.setpId(project.getId());
		
		//查询点评信息
//		List<ProjectCommentsDTO>  projectCommentsList =   projectCommentsServiceImpl.queryProjectComments(projectComments); 
		
		//查询年化益率信息
		List<ProjectAnnualRevenueDTO> projectAnnualRevenueList = projectAnnualRevenueServiceImpl.queryProjectAnnualRevenue(project.getId());
		
		ProjectRabateDTO projectRabateDTO = new ProjectRabateDTO();
		projectRabateDTO.setpId(project.getId());
		List<ProjectRabateDTO>  projectRabateList = projectRabateSericeImpl.queryProjectRabate(projectRabateDTO);
		
		ProjectRiskDTO projectRiskDto = new ProjectRiskDTO();
		projectRiskDto.setpId(project.getId());
		List<ProjectRiskDTO> projectRiskList = projectRiskServiceImpl.queryProjectRisk(projectRiskDto);
		
		List<ProjectAccountDTO>  projectAccountList = projectAccountServiceImpl.queryProjectAccountList(project.getId());
		
		Map<String,Object> projectMap = new HashMap<String,Object>();
		
		try {
			CorpProjectDTO corpProjectDTO = projectServiceImpl.queryCorpProject(project.getId());
			if(corpProjectDTO != null &&  corpProjectDTO.getFpCorpId() != null && 0!=corpProjectDTO.getFpCorpId() ){
				CompanyDTO companyDTO = new CompanyDTO();
				companyDTO.setId(corpProjectDTO.getFpCorpId());
				projectMap.put("projectCorpList",companyServiceImpl.listCompany(companyDTO));
			}
		} catch (SQLException e) {
			log.error("query project corp error:",e);
		}
		
		projectMap.put("project", project);
		projectMap.put("projectRiskList", projectRiskList);
		projectMap.put("projectRabateList", projectRabateList);
		projectMap.put("projectAnnualRevenueList", projectAnnualRevenueList);
		projectMap.put("projectAccountList", projectAccountList);
//		projectMap.put("projectCommentsList", projectCommentsList);
		return new ModelAndView("projectVerifyModify",projectMap);
	}
	
	@RequestMapping("/updateProjectForVerify.shtml")
	public ModelAndView updateProjectForVerify(HttpServletRequest request,
			HttpServletResponse response,ProjectDTO projectDTO) {
		
		DTOdateSet.setUpdateInfo(projectDTO, request.getSession());
		int project = 0;
		try {
			project = projectServiceImpl.updateProject(projectDTO,null);
		} catch (SQLException e) {
			log.error("update project error !",e);
		}
		
		Map<String,Object> resultMap = new HashMap<String,Object>();
		resultMap.put(Dict.result, project);
		
		return new ModelAndView("projectVerifyModifyResult",resultMap);
	}
	
	@RequestMapping("/addProductRecommend.shtml")
	@ResponseBody
	public Map<?,?> addProductRecommend(HttpServletRequest request,
			HttpServletResponse response,ProductRecommendDTO productRecommendDto) {
		productRecommendDto.setRecommendDate(new Date());
		productRecommendDto.setFaId("0");
		DTOdateSet.setCreateInfo(productRecommendDto, request.getSession());
		DTOdateSet.setUpdateInfo(productRecommendDto, request.getSession());
		int result = productRecommendServiceImpl.addProductRecommend(productRecommendDto);

		Map<String,Object> resultMap = new HashMap<String,Object>();
		resultMap.put(Dict.result, result);
		resultMap.put("recommendleve", productRecommendDto.getRecommendWeight());
		
		return resultMap;
	}
	
	@RequestMapping("/productRecommendList.shtml")
	@ResponseBody
	public Map<?,?> productRecommendList(ProductRecommendDTO productRecommendDto){
		Map<String,Object> productRecommendMap = new HashMap<String,Object>();
		
		productRecommendMap.put("productRecommendList",productRecommendServiceImpl.queryProductRecommendList(productRecommendDto));
		productRecommendMap.put(Dict.result, Dict.result_success);
		
		return productRecommendMap;
	}
	
	@RequestMapping("/productSet.shtml")
	public ModelAndView productSet(HttpServletRequest request,
			HttpServletResponse response,ProjectDTO project) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		resultMap.put(Dict.result, 0);
		try{
			project.setpSaleStatus(Dict.pSaleStatus_end);
			if(project.getId() != null){
				DTOdateSet.setUpdateInfo(project, request.getSession());
				resultMap.put(Dict.result, projectServiceImpl.projectSet(project));
			}
		}catch(Exception e){
			log.error("product set  error",e);
		}
		
		return new ModelAndView("productSetResult",resultMap);
	}
	
	@RequestMapping("/validatoProjectCode")
	@ResponseBody
	public Map<?,?> validatoProjectCode(ProjectDTO project){
		
		Map<String,Object> result = new HashMap<String,Object>();
		List<ProjectDTO> projectList = projectServiceImpl.queryAllProject(project);
		
		if(projectList!= null && projectList.size()>0){
			result.put(Dict.result, false);
		}else{
			result.put(Dict.result, true);
		}
		return result;
	}
	
	@RequestMapping("/projectAllSubscription.shtml")
	@ResponseBody
	public Map<?,?> projectAllSubscription(ProjectDTO project){
		
		Map<String,Object> result = new HashMap<String,Object>();
		
		Integer resultInt = null;
		try {
			project.setpAllSubscriptionAmount(project.getpAllSubscriptionAmount().multiply(new BigDecimal(10000)));
			resultInt = projectServiceImpl.updateAllSubscription(project);
		} catch (SQLException e) {
			resultInt = 0;
			log.error("update project all subscription error!",e);
		}
		
		result.put(Dict.result, resultInt);
		result.put("pAllSubscriptionAmount", project.getpAllSubscriptionAmount());
		result.put("pAllSubscriptionNum", project.getpAllSubscriptionNum());
		return result;
	}
	
}
